var pathRequestUrl;
var START_INDEX = 2;

Ext.onReady(function(){
    Ext.QuickTips.init();
    pathRequestUrl = 'ImportExcelSinger_Data.php';
    
    var dataSinger = new Ext.FormPanel({
        frame: true,
        title: 'Import Excel thông tin ca sỹ',
        width: 500,
        renderTo: 'ListSingerTables',
        iconCls: 'form-icon',
        url: pathRequestUrl,
        fileUpload: true,
        items: [{
            width: 400,
            xtype: 'fileuploadfield',
            id: 'fileupload',
            emptyText: 'Chọn excel file',
            fieldLabel: 'Chọn file',
            name: 'fileupload',
            allowBlank: false,
            //accept: 'vnd.ms-excel',
            buttonCfg: {
                text: '',
                iconCls: 'upload-icon'
            },
            allowBlank: false,
            anchor: '95%'
        }, {
            xtype: 'radiogroup',
            fieldLabel: 'Loại sheet',
            width: 300,
            items: [{
                boxLabel: 'Một sheet',
                name: 'SheetType',
                inputValue: 1,
                checked: true
            }, {
                boxLabel: 'Nhiều sheet',
                name: 'SheetType',
                inputValue: 2
            }],
            listeners: {
                change: function(e){
                    if (e.getValue().inputValue == 1) {
                        Ext.getCmp('SheetIndex').setValue(0);
                        Ext.getCmp('SheetIndex').setDisabled(true);
                    }
                    else {
                        Ext.getCmp('SheetIndex').setDisabled(false);
                    }
                }
            }
        }, {
            xtype: 'numberfield',
            labelStyle: 'width:120',
            width: 90,
            name: 'SheetIndex',
            id: 'SheetIndex',
            fieldLabel: 'Sheet thứ',
            disabled: true,
            value: 0,
            allowBlank: false,
            minValue: 0
        }, {
            xtype: 'numberfield',
            labelStyle: 'width:120',
            width: 90,
            name: 'StartRow',
            id: 'StartRow',
            fieldLabel: 'Dòng bắt đầu',
            value: START_INDEX,
            allowBlank: false,
            minValue: 0
        }],
        buttons: [{
            text: 'Đồng ý',
            handler: function(){
                if (!dataSinger.getForm().isValid()) {
                    return;
                }
                try {
                    dataSinger.getForm().submit({
                        method: 'POST',
                        success: function(f, a){
                            var result = Ext.util.JSON.decode(a.response.responseText);
                            msg('Thông tin', result.msg.content, Ext.MessageBox.INFO);
                        },
                        failure: function(f, a){
                            var result = Ext.util.JSON.decode(a.response.responseText);
                            msg('Lỗi', result.msg.error, Ext.MessageBox.ERROR);
                        }
                    });
                    execWithProgress('Đang trong quá trình xử lí.');
                } 
                catch (e) {
                    console.debug(e);
                }
            }
        }, {
            text: 'Hủy'
        }]
    });
});
